<?php 
header("charset=utf-8");
require_once('../../includes/classes/core.php');
require_once('../../includes/functions.php');
$user_id		= $_SESSION['USERID'];
$warehouse_id	= $_REQUEST['id'];?>
<!DOCTYPE meta PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>

	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">	
	<script type="text/javascript" language="javascript" src="../../js/jquery-1.9.1.min.js"></script>
	
	<script type="text/javascript" language="javascript" src="../../js/jquery-ui-1.10.3.custom.min.js"></script>
	<!-- <script type="text/javascript" language="javascript" src="../../js/jquery.mobile-1.2.0.min.js"></script> -->	
	<script type="text/javascript" language="javascript" src="../../js/jquery.ui.datepicker-ka.min.js"></script>
	
	<script type="text/javascript" language="javascript" src="../../js/jquery.dataTables.min.js"></script>
	<script type="text/javascript" language="javascript" src="../../js/TableTools.min.js"></script>
	<script type="text/javascript" language="javascript" src="../../js/jquery.dataTables.columnFilter.js"></script>
	<script type="text/javascript" language="javascript" src="../../js/ColReorderWithResize.js"></script>
	<script type="text/javascript" language="javascript" src="../../js/dataTables.action.js"></script>
	
	<!-- Plugins -->
	<script type="text/javascript" language="javascript" src="../../js/jquery-ui-timepicker-addon.js"></script>
	<script type="text/javascript" language="javascript" src="../../js/jquery-ui-timepicker-ka.js"></script>
	<script type="text/javascript" language="javascript" src="../../js/jquery-ui-sliderAccess.js"></script>
	<script type="text/javascript" language="javascript" src="../../js/jquery.cookie.js"></script>
	<script type="text/javascript" language="javascript" src="../../js/jquery.hoverIntent.minified.js"></script>
	
	<script type="text/javascript" language="javascript" src="../../js/ajaxfileupload.js"></script>
	<script type="text/javascript" language="javascript" src="../../js/phpjs.js"></script>
	
	<script type="text/javascript" src="../../js/jNotify.jquery.min.js"></script>
		<!-- Main -->
	<link rel="stylesheet" href="../../media/css/datatable.css" type="text/css" />
	<link rel="stylesheet" href="../../media/css/datatable_forms.css" type="text/css" />
	<link rel="stylesheet" href="../../media/css/datatable_inner_tables.css" type="text/css" />
	<link rel="stylesheet" href="../../media/css/datatable_loading.css" type="text/css" />
	<link rel="stylesheet" href="../../media/css/datatable_pos.css" type="text/css" />
	<link rel="stylesheet" href="../../media/css/datatable_seoy.css" type="text/css" />
	<link rel="stylesheet" href="../../media/css/datatable_table.css" type="text/css" />
	<link rel="stylesheet" href="../../media/css/datatable_tree.css" type="text/css" />
	
	<!-- Plugins -->
	<link rel="stylesheet" href="../../media/css/TableTools_JUI.css" type="text/css" />
	<link rel="stylesheet" href="../../media/css/jquery-ui-timepicker-addon.css" type="text/css" />
	<link rel="stylesheet" href="../../media/css/jNotify.jquery.css" type="text/css" />
	
	<!-- jQuery UI -->
	<link rel="stylesheet" href="../../media/themes/jQuery-UI/redmond/jquery-ui.min.css" type="text/css" />
	<link rel="stylesheet" href="../../media/themes/jQuery-UI/redmond/jquery-ui.datatable.css" type="text/css" />
	<!-- <link rel="stylesheet" href="../../media/themes/jQuery-Mobile/default/jquery.mobile-1.2.0.css" type="text/css" /> -->
	 <style type="text/css">
        table, td, th {
            padding: 0 5px;
            border-collapse: collapse;
            border: 1px solid #000;
            text-align: center;}	
        td:nth-child(5){
        text-align: right; }    
    </style>
    <script type="text/javascript">
    var jsons = (<?php        $query=mysql_query("SELECT * FROM `company_bank_requisites`");
    
                                while ($row = mysql_fetch_array( $query ) ) {
                                    $arr[]=$row;
                                    $arr[bank].="<option value='$row[0]'>$row[1]</option>";
                                    };
                                echo json_encode($arr);
                                ?>);
    
       console.log(jsons);
    $(document).ready(function(){
    	shecvla(0);  
        $("#bank").html(jsons.bank);
        
        $("#bank").change(function(){
        	id=$(this).val()-1;
        	shecvla(id);    
            });
        
   	 $( "#date").datepicker({
         numberOfMonths: 1          
     });
     var date=      $("#date").val();
     $("#date").datepicker("option", $.datepicker.regional["ka"]);
     $("#date").datepicker("option", "dateFormat", "d  MM  yy");
     $("#date").datepicker( "setDate", date );
   //  $('body').attr('contenteditable','true');
  	});
  	function shecvla(id){
        bank_code="ბანკის კოდი: "+jsons[id][2];
        number  = "ანგარიში:    "+jsons[id][3];
    	$("#bank_code").html(bank_code);
    	$("#number").html(number); 
  	  	}
  	
  	
    </script>
</head>    
<body style="width: 21cm">
    <img style="font-family: Sylfaen, Arial, sans-serif; font-size: 13px; font-weight: bold; text-align: center; float: left;" src="logo.jpg" alt="" width="76" height="76" />
    <span style="font-size: x-large;"><strong>GS Unity<span style="font-size: xx-large; float:right;">ინვოისი</span></strong></span>
    <p style="text-align: right;">
    <input id="date" style="font-size: medium; border: none; text-align: right;"> 
    </p>
    <p style="text-align: right;"><span style="font-size: medium;" contenteditable="true">N 0035 </span></p>
    <span style="font-size: medium;"><br />ქ. თბილისი; ა. პოლიტკოვსკაიას 10<br /></span>
    <span style="font-size: medium;">ტელ: 2-555-118<br /></span>
    <span style="font-size: medium;">ელ-ფოსტა: <strong>service@gsunity.ge</strong><br /></span>
    <br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
    <span style="font-size: medium;">გაცემულია  </span>
    <span style="float: right;"> პროდუქტი/მომსახურება:</span><br />
<?php  
$client='';
   $id=$_REQUEST[id];       
   $rResult = mysql_query("
            SELECT  'კარტრიჯი',
            		'დამუხტვა',
            		COUNT(b_letter_details.id),
            		sum(IF(warehouse_detail.type=2 AND b_letter_details.part_type_id=2,0.00,b_letter_details.price)) as tax,
            		max(client.`name`) as client
            FROM warehouse_detail 
            JOIN b_letter_details ON b_letter_details.warehouse_detail_id=warehouse_detail.id
            JOIN client ON SUBSTR(b_letter_details.barcode, 2, 4) = client.id
            WHERE warehouse_detail.type != 2 AND warehouse_detail.actived=1 AND warehouse_id in ($id) 
            
            UNION ALL
            
            SELECT  'პრინტერი',
            		'შეკეთება',
            		COUNT(e_letter_details.id),
            		sum(e_letter_details.price) as tax,
            		max(client.`name`) as client
            FROM warehouse_detail 
            JOIN e_letter_details ON e_letter_details.warehouse_detail_id=warehouse_detail.id
            JOIN client ON SUBSTR(e_letter_details.barcode, 2, 4) = client.id
            WHERE warehouse_detail.type != 2 AND warehouse_detail.actived=1 AND warehouse_id in ($id)
                   
");
   while ( $aRow = mysql_fetch_array( $rResult ) )
   {
       if ($aRow[tax]>0) {
           $cartrije.= "<tr><td>$aRow[0]</td><td>$aRow[1]</td><td>$aRow[2]</td><td>$aRow[3]</td></tr>";
           $sum+=$aRow[tax];
           $client=$aRow[client];
       }
       
       
      
   }
 
   
        ?>
    <span style="font-size: medium; "><strong>ს.ს "<?php echo $client ?>"</strong>  </span>
    <span style="float: right;"><strong>საბეჭდი მოწყობილობის სერვისი</strong></span>
    <br /><br /><br />    
    <table style="margin: auto; width: 20cm;">
      <tr>
        <th>დასახელება</th>
        <th>შესრულებული სამუშაო</th>
        <th>რაოდენობა</th>
        <th>ღირებულება</th>
      </tr>
    <?php 
     echo $cartrije;  

    ?>
    </table>
    <div style="padding: 20px; font-size:20px; text-align: right; width: 90%;">საერთო ჯამი :
    <?php echo number_format((float)$sum,2, '.', '');?>
    </div>
    
    <strong><br /><br />&nbsp;<span style="font-size: medium;">ჩვენი რეკვიზიტებია:</span></strong>
    <span style="font-size: medium;">შპს "ჯი ეს იუნიტი"</span><br /><span style="font-size: medium;">საიდ. კოდი 205258219<br /></span>   
    <select style="font-size: medium; border: none;" id="bank">
    </select><br />
    <span style="font-size: medium;" id='bank_code'></span><br />
    <span style="font-size: medium;" id="number"></span>
    <p style="text-align: right;"><span style="font-size: medium;">დირექტორი:________________________________________</span></p>
<p style="text-align: center;"><span style="font-size: medium;">გმადლობთ თანამშრომლობიშთვის &nbsp; &nbsp; &nbsp; &nbsp;</span></p>
</body>
</html>